import {
  SET_FULL_SCREEN,
  SET_MINI_PLAYER,
  SET_IS_PLAYING,
  SET_MODE_TYPE,
  SET_LIST_PLAYER,
  SET_SONG_DETAIL,
  SET_LYRIC,
  SET_DEL_SONG,
  SET_CURRENT_INDEX,
  SET_CURRENT_TIME
} from './mutations-type'
export default {
  // changeFullScreen (state, flag) {
  //   state.isFullScreen = flag
  // }
  // 全屏播放界面
  [SET_FULL_SCREEN] (state, flag) {
    state.isFullScreen = flag
    // 如果全屏播放界面显示 迷你和列表界面就要关闭 同理可证其他
    if (flag) {
      state.isMiniPlayer = false
      state.isListPlayer = false
    }
  },
  // 迷你界面的显示
  [SET_MINI_PLAYER] (state, flag) {
    state.isMiniPlayer = flag
    if (flag) {
      state.isFullScreen = false
      state.isListPlayer = false
    }
  },
  // 暂停/播放按钮
  [SET_IS_PLAYING] (state, flag) {
    state.isPlaying = flag
  },
  // 循环模式
  [SET_MODE_TYPE] (state, flag) {
    state.modeType = flag
  },
  // 列表播放界面
  [SET_LIST_PLAYER] (state, flag) {
    state.isListPlayer = flag
    if (flag) {
      state.isFullScreen = false
      state.isMiniPlayer = false
    }
  },
  [SET_SONG_DETAIL] (state, list) {
    state.songs = list
  },
  // 获取歌词
  [SET_LYRIC] (state, lyric) {
    state.currentLyric = lyric
  },
  // 删除单个歌曲
  [SET_DEL_SONG] (state, index) {
    if (index !== undefined) {
      // 删除单个
      state.songs.splice(index, 1)
    } else {
      // 什么都没传删除所有
      state.songs = []
    }
    // 判断当前的index是不是小于列表的长度 如果是index赋值为列表长度-1  解决删除列表歌曲正在播放前面歌曲的时候 图标位置错乱的问题
    if (index < state.currentIndex) {
      state.currentIndex = state.currentIndex - 1
    }
    if (state.songs.length === 0) {
      state.isFullScreen = false
      state.isMiniPlayer = false
      state.isListPlayer = false
    }
  },
  [SET_CURRENT_INDEX] (state, index) {
    // 如果是第一首 变成最后一首
    if (index < 0) {
      index = state.songs.length - 1
    } else if (index > state.songs.length - 1) {
      index = 0
    }
    state.currentIndex = index
  },
  [SET_CURRENT_TIME] (state, time) {
    state.curTime = time
  }
}
